﻿using System;
using System.Collections.Generic;

namespace SimpleServiceBus.Bus.Pipeline.PipelineComponents.Routing
{
    public class SimpleMessageRouter : MessageRouterComponentBase
    {
        private readonly List<IMessageRoute> _routes = new List<IMessageRoute>();

        public List<IMessageRoute> Routes { get { return _routes; } }

        protected override string[] GetDestinationsForMessage(MessageEnvelope messageEnvelope, IMessageContext context)
        {
           foreach (IMessageRoute route in Routes)
           {
               if (route.Matches(messageEnvelope))
                   return route.Destinations;
           }
           return new string[0];
        }
    }
}